package com.taotao.wifepojie.test;


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String target = sc.nextLine();	//target
        String source= sc.nextLine();	//source
      /*  String target = "abcaybec";
        String source = "abc";*/
        source = reorder(source);
        int size = source.length();
        for (int i = 0; i <size; i++) {
            String ss = source.substring(i, i + 1);
            int last = target.lastIndexOf(ss);
            if(last>0){
                String str  = target.substring(0, last);
                if (i == size-1) {
                    System.out.println(str.length());
                }
            }


        }

    }

    private static String reorder(String str) {
        return new StringBuffer(str).reverse().toString();
    }
}